package com.ejlchina.tool.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.adolf.androiddemo.R
import com.adolf.androiddemo.databinding.ItemConfigWarningBinding
import com.ejlchina.tool.bean.ConfigWarningBean

class ConfigWarningAdapter(private val dataList: List<ConfigWarningBean>): RecyclerView.Adapter<ConfigWarningAdapter.ConfigWarningViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ConfigWarningViewHolder {
        val binding = ItemConfigWarningBinding.inflate(LayoutInflater.from(parent.context),parent,false)
        return ConfigWarningViewHolder(binding)
    }

    override fun getItemCount(): Int {
        return dataList.size
    }

    override fun onBindViewHolder(holder: ConfigWarningViewHolder, position: Int) {
        holder.bindData(dataList[position])
    }

    inner class ConfigWarningViewHolder(private val binding: ItemConfigWarningBinding) :RecyclerView.ViewHolder(binding.root){
        fun bindData(configWarningBean: ConfigWarningBean){
            binding.tvTitle.text = configWarningBean.key
            binding.tvValue.text = configWarningBean.value
            val resId = if (configWarningBean.isNormal) R.color.title_text_color else R.color.color_text_red
            binding.tvValue.setTextColor(binding.root.resources.getColor(resId,null))
        }
    }
}